import Vue from "vue";
import Vuex from "vuex"

Vue.use(Vuex)

const store = new Vuex.Store({
  strict: true,
  state: {
    //如果缓存中有，则调用缓存中的token，没有则设空字符
    STUDENTID: localStorage.getItem('STUDENTID') ? localStorage.getItem('STUDENTID') : '',
    TOKEN: localStorage.getItem('TOKEN') ? localStorage.getItem('TOKEN') : '',
    LOADINGMESSAGE:''
  },
  mutations: {
    updateToken(state, data) {
      console.log('update token',data)
      state.STUDENTID = data.studentId
      state.TOKEN = data.token
      localStorage.setItem('STUDENTID', state.STUDENTID)
      localStorage.setItem('TOKEN', state.TOKEN)
    },
    deleteToken(state) {
      state.STUDENTID = ''
      state.TOKEN = ''
      localStorage.setItem('STUDENTID', '')
      localStorage.setItem('TOKEN', '')
    },
    updateMessage(state,data){
      state.LOADINGMESSAGE+=data
    },
    clearMessage(state){
      state.LOADINGMESSAGE=''
    }
  }
})

export default store